package leetcode.L279;

import java.util.Arrays;

class Solution1 {
    public int numSquares(int n) {
        //和为n的完全平方数的最小数量
        int[] dp = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {//背包
            for (int j = 1; j * j <= i; j++) {//物品
                dp[j] = Math.min(dp[i - j * j] + 1, dp[i]);
            }
        }
        return dp[n];
    }
}
